<?php
require_once($application_folder."/controllers/navigator.php");
class Horoscope extends Navigator{

    function __construct(){
        parent::__construct();
        
        /************************************************************
        * CHECK LOGIN
        *************************************************************/
        if(!$this->session->userdata('logged_in')){
            redirect(base_url());
        }
        
        $this->load->helper('date');
    }

    function index(){
        $this->preview();
    }

    function preview(){

        /************************************************************
        * GET Caricature
        *************************************************************/
        $data['horoscope'] = $this->db->get('horoscope')->result_array();

        $this->core_cms('horoscope', $data, 'preview');                                  
    }

    function newform(){

        $data = array();

        /************************************************************
        * GET Caricature if Edit MODE
        *************************************************************/
        if(isset($_GET['id'])){
            $data['horoscope'] = $this->db->get_where('horoscope', array('id' => $_GET['id']))->result_array();    
        }

        $this->core_cms('horoscope', $data, 'new_edit_form');                                  
    }

    function edit_insert(){


        switch ($_POST['appmode']){

            case 'insert':
                unset($_POST['appmode']);
                unset($_POST['id']);
                $_POST['datetime'] = strtotime($_POST['datetime']);
                $this->db->insert('horoscope', $_POST);
                echo json_encode(array('action'=> true)); 
                break;

            case 'edit':
                unset($_POST['appmode']);
                $this->db->where('id', $_POST['id']);
                unset($_POST['id']); 
                $_POST['datetime'] = strtotime($_POST['datetime']); 
                $this->db->update('horoscope', $_POST);
                echo json_encode(array('action'=> true));

                break;

        }

    }

    function deleteone(){

        $this->db->where('id',$_POST['id']);
        $this->db->delete('horoscope');
        echo json_encode(array('action'=> true));
    }
}